#pragma once

#include <QGraphicsView>
#include <QPainter>
#include <QWheelEvent>

class SceneViewer : public QGraphicsView
{
    Q_OBJECT
public:
    explicit SceneViewer(QWidget *parent = nullptr);

    // 网格配置方法
    void setGridVisible(bool visible);

    void setGridStyle(const QColor &majorColor, const QColor &minorColor,
                      int majorSpacing, int minorSpacing, int lineWidth = 1);

    void setGridDensity(int density); // 控制缩放时的网格密度

    bool isGridVisible() const;

protected:
    void drawBackground(QPainter *painter, const QRectF &rect) override;

    void wheelEvent(QWheelEvent *event) override;

private:
    void drawGrid(QPainter *painter, const QRectF &rect);

    qreal calculateEffectiveSpacing(qreal baseSpacing) const;

    bool m_gridVisible = true;
    QColor m_majorGridColor = QColor(60, 60, 60, 100); // 主网格颜色
    QColor m_minorGridColor = QColor(40, 40, 40, 50); // 次网格颜色
    int m_majorGridSpacing = 100; // 主网格间距(像素)
    int m_minorGridSpacing = 20; // 次网格间距(像素)
    int m_gridLineWidth = 1;
    int m_gridDensity = 1; // 网格密度系数
    qreal m_currentScale = 1.0; // 当前缩放因子
};
